package com.example.behaviour.feign;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.apis.behaviour.IBehaviourClient;
import com.example.behaviour.mapper.AclUserFanMapper;
import com.example.behaviour.mapper.ApUserFollowMapper;
import com.example.model.common.dtos.ResponseResult;
import com.example.model.user.pojos.AclUserFan;
import com.example.model.user.pojos.ApUserFollow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
public class BehaviourClient implements IBehaviourClient {

    @Autowired
    private AclUserFanMapper aclUserFanMapper;

    @Autowired
    private ApUserFollowMapper apUserFollowMapper;

    @Override
    @PostMapping("/feign/v1/behaviour/fansList")
    public ResponseResult getFansList(@RequestParam("userId") Integer userId) {
        QueryWrapper queryWrapper = new QueryWrapper<AclUserFan>();
        queryWrapper.eq("user_id",userId);

        List list = aclUserFanMapper.selectList(queryWrapper);
        System.out.println("user_id "+userId);
        System.out.println(Arrays.toString(list.toArray()));
        return ResponseResult.okResult(list);
    }

    @Override
    @PostMapping("/feign/v1/behaviour/isFollowed")
    public boolean isFollowed(@RequestParam("userId") Integer userId,@RequestParam("followId") Integer followId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("follow_id",followId);
        queryWrapper.eq("user_id",userId);
        ApUserFollow apUserFollow = apUserFollowMapper.selectOne(queryWrapper);
        if(apUserFollow != null){
            return true;
        }else {
            return false;
        }
    }
}
